package com.sharker.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.sharker.R;
import com.sharker.adapter.TablayoutViewpagerAdapter;
import com.sharker.fragment.CourseDetaildfragment;
import com.sharker.view.Toptitlebar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CourseDetailActivity extends AppCompatActivity {
    @BindView(R.id.cd_tablayout)
    TabLayout cdTablayout;
    @BindView(R.id.cd_viewpager)
    ViewPager cdViewpager;
    @BindView(R.id.try_titlebar)
    Toptitlebar tryTitlebar;
    private List<Fragment> flist;
    private List<String> list;
    private String object_id;
    private Toptitlebar toptitlebar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_detail);
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
        ButterKnife.bind(this);
        toptitlebar = new Toptitlebar(CourseDetailActivity.this);
        initview();
        initData();
        cdViewpager.setAdapter(new TablayoutViewpagerAdapter(getSupportFragmentManager(), CourseDetailActivity.this, flist, list));
        cdTablayout.setupWithViewPager(cdViewpager);
        tryTitlebar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    private void initview() {
        Intent intent = getIntent();
        object_id = intent.getStringExtra("object_id");
        list = new ArrayList<>();
        list.add("精品");
        list.add("美容");
        list.add("美甲");
        list.add("按摩");
        list.add("培训");
    }
    private void initData() {
        flist = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Bundle bundle = new Bundle();
            bundle.putInt("num", i);
            bundle.putString("id", object_id);
            CourseDetaildfragment detaildfragment = new CourseDetaildfragment();
            detaildfragment.setArguments(bundle);
            flist.add(detaildfragment);
        }
    }

}
